from seleniumwire import webdriver  # 导入seleniumwire的webdriver
import time
import pyautogui
import json
import re
import src.util.nacos.nacos_client as nacos_client  # 导入nacos模块
from src.util.log_util.log import logging  # 导入日志模块
from src.upload import click_upload  # 导入上传模块
import requests
import src.infoinit as infoinit
import pyperclip
import logging

logging.basicConfig(level=logging.DEBUG)
logger=logging.getLogger('seleniumwire')

def init():
    # 设置seleniumwire的选项，注意这是一个字典而非ChromeOptions实例
    seleniumwire_options = {
        #'suppress_connection_errors':False,
        'auto_config':True,
        'enable_har':True
    }

    options = webdriver.ChromeOptions()
    options.add_argument("start-maximized")  # 最大化窗口
    # 获取配置的位置
    chrome_url = nacos_client.get_value("chrome_url")
    if chrome_url:
        options.binary_location = chrome_url
    options.executable_path=nacos_client.get_value("chromedriver_url")
    # 设置seleniumwire的webdriver
    driver = webdriver.Chrome(
        seleniumwire_options=seleniumwire_options,
        options=options
    )
    
    # 访问网页
    driver.get("http://129.0.13.246:8081/eams/loginAfterAuth")  # 确保使用https://
    dangan_login(driver)
    time.sleep(3) 
    return driverzhaoyue2

# 登陆档案系统
def dangan_login(driver):
    pyautogui.hotkey('ctrl', 'l')
    time.sleep(1) 
    pyperclip.copy('http://129.0.13.246:8081/eams/loginAfterAuth')
    pyautogui.hotkey('ctrl', 'v')
    pyautogui.press('enter')
    time.sleep(2) 
    # 账户zhaoyue123456
    pyperclip.copy('zhaoyue2')
    #pyautogui.click(993, 346)
    pyautogui.click(1250, 456)
    time.sleep(1)
    pyautogui.hotkey('ctrl', 'v')
    #driver.execute_script('document.getElementById("usernamefm3").value = "zhaoyue2";')
    # 密码
    pyautogui.click(1250, 546)
    pyperclip.copy('zhaoyue123456')
    time.sleep(1)
    pyautogui.hotkey('ctrl', 'v')
    #driver.execute_script('document.getElementById("passwordfm3").value = "zhaoyue123456";')
    # 点击登陆
    time.sleep(1) 
    driver.execute_script('document.getElementById("btnLoad3").click();')
    time.sleep(1)

    #下一步查询操作
    infoinit.choice(driver);



